<br/>
<form id="ndk-health-form" method="post" action="<?php echo Yii::app()->createUrl('soa/showSoaInternal'); ?>" target="_blank">
	<div class="row">
		<div class="col-md-4">
			<div class="widget box">
				<div class="widget-header">
					<h4><i class="icon-reorder"></i> Laporan SOA to Internal</h4>
				</div>
				<div class="widget-content">
				<div class="control-group">
					<label class="control-label">
					Nama Marketing
					<span class="required">*</span>
					</label>
					<div class="controls">
						<div class="input-group">
							<?php 
echo CHtml::dropDownList('mySelect', '12', CHtml::listData(MstMarketing::model()->findAll(), 'id','name'),array("empty"=>"--Pilih Marketing--","class"=>"form-control"));							?>
						</div>
					</div>
				</div>
				<div class="control-group">
					<label class="control-label">
					Perusahaan Asuransi 
					<span class="required">*</span>
					</label>
					<div class="controls">
						<div class="input-group">
							<?php 
echo CHtml::dropDownList('nama_client', '12', CHtml::listData(MstPerusahaanAsuransi::model()->findAll(), 'id','name'),array("empty"=>"--Pilih--","class"=>"form-control"));							?>
							
						</div>
					</div>
				</div>
				<div class="control-group">
					<label class="control-label">
					<span class="required"><!--* (Jika Bayar kurang Rp 5000 maka force mary, jk kurang bayar maka O/S)--></span>
					</label>
					<div class="controls">
						<div class="input-group">
							
						</div>
					</div>
				</div>
				</div>
		</div>
	</div>
	</div>
	
	<div class="row">
		<div class="col-md-2">
		<input type="button" class="btn btn-default btn-warning" id="btn_show_cicil" value="Preview"> 
		<button class="btn btn-primary btn-large" name="yt0" type="submit"><i class="icon-fixed-width">&#xf02f</i>Cetak</button>
		</div>
	</div>
</form>	
<br/>
	<div class="row">
					<div class="col-md-12">
						<div class="widget box">
							<div class="widget-header">
								<h4><i class="icon-reorder"></i> List Cicilan </h4>
								<div class="toolbar no-padding">
									<div class="btn-group">
										<span class="btn btn-xs widget-collapse"><i class="icon-angle-down"></i></span>
									</div>
								</div>
							</div>
							<div class="widget-content no-padding">
								<table id="tbl_cicilan" class="table table-striped table-bordered table-hover table-checkable table-responsive ">
									<thead>
										<tr>
											
											<th data-class="expand">No. Polish </th>
											<th>No. DN/CN</th>
											<th>Ins. Type</th>
											<th>Ins. Name</th>
											<th>Inception Date</th>
											<th>Aging</th>
											<th>Curr</th>
											<th>Gross Premium</th>
											<th>Discount</th>
											<th>Polish Cost</th>
											<th>Stamp Duty</th>
											<th>Brokerage</th>
											<th>VAT</th>
											<th>Income Tax</th>
											<th>Net. Premium</th>
											<th>Type</th>
											<th>Status</th>
										</tr>
									</thead>
									<tbody id="isi_cicilan">
									</tbody>
								</table>
							</div>
						</div>
					</div>
				</div>
				

<div id="modalProcess" class="modal fade in" style="display: none;" aria-hidden="false">
												<div class="modal-dialog" style="width:250px;">
													<div class="modal-content">
														<div class="modal-body">
															<div class="alert alert-info fade in" id="div_process">
															Waiting Process..
															</div>
															<div class="alert alert-info fade in" id="div_sukses" style="display:none;">
															Success Process..
															</div>
														</div>
														<div class="modal-footer">
															<button data-dismiss="modal" class="btn btn-default" type="button">Close</button>
															
														</div>
													</div><!-- /.modal-content -->
												</div><!-- /.modal-dialog -->
											</div>

<script type="text/javascript">
function formatCurrency(total) {
    var neg = false;
    if(total < 0) {
        neg = true;
        total = Math.abs(total);
    }
    return (neg ? "" : '') + parseFloat(total, 10).toFixed(2).replace(/(\d)(?=(\d{3})+\.)/g, "$1,").toString();
}
$("#btn_show_cicil").click(function(e){
	var status = "";
	var action = "";
	var isi_cicilan = "";
	$.ajax({
			type:"POST",
            url:"<?php echo Yii::app()->createUrl('/Soa/showSoaInternal'); ?>",
			data:"txt_client_no="+$("#txt_client_no").val()+"&cb_jnsAsuransi="+$("#cb_jnsAsuransi").val(),
			dataType:"json",
            success:function(data){
				for(var i=0;i<data.jsonShowInternal.length;i++){
					
					if(data.jsonShowInternal[i].status == 'Marry On Gross'){
						status = "<span class='label label-success'>Marry On Gross</span>";
					}
					if(data.jsonShowInternal[i].status == 'O/S'){
						status = "<span class='label label-danger'  >O/S</span>";
					}
					if(data.jsonShowInternal[i].status == 'Force Marry'){
						status = "<span onClick='forceMarry("+data.jsonShowInternal[i].id+",\""+data.jsonShowInternal[i].nota_debet_no+"\","+data.jsonShowInternal[i].kurang_bayar+","+data.jsonShowInternal[i].no_type+")'  class='label label-warning'>Force Marry</span>";
					}
					
					isi_cicilan += "<tr>" +
					"<td>"+data.jsonShowInternal[i].policy_no+"</td>"+
					"<td>"+data.jsonShowInternal[i].nota_debet_no+"</td>"+
					"<td>"+data.jsonShowInternal[i].type+"</td>"+
					"<td>"+data.jsonShowInternal[i].name+"</td>"+
					"<td>-</td>"+
					"<td>-</td>"+
					"<td>-</td>"+
					"<td>"+formatCurrency(data.jsonShowInternal[i].nominal)+"<br> Konv. Rp. "+formatCurrency(data.jsonShowInternal[i].nominal_konv)+" <br> <span class='label label-primary'> "+formatCurrency(data.jsonShowInternal[i].jml_bayar)+"</span></td>"+
					"<td>"+formatCurrency(data.jsonShowInternal[i].discount)+"</td>"+
					"<td>"+formatCurrency(data.jsonShowInternal[i].policy_cost)+"</td>"+
					"<td>"+formatCurrency(data.jsonShowInternal[i].stamp_duty)+"</td>"+
					"<td>"+formatCurrency(data.jsonShowInternal[i].brokerage)+"</td>"+
					"<td>-</td>"+
					"<td>-</td>"+
					"<td>"+formatCurrency(data.jsonShowInternal[i].nett_to_insurance)+"<br> Konv. Rp. "+formatCurrency(data.jsonShowInternal[i].nett_to_insurance_konv)+" <br> <span class='label label-primary'>"+data.jsonShowInternal[i].jml_bayar+"</span></td>"+
					"<td>-</td>"+
					"<td>"+status+"</td>"+
					"</tr>";
				}
				$("#isi_cicilan").html(isi_cicilan);
			}
	});
});//end click

function forceMarry(id,nota_debet_no,kurang_bayar,no_type){
	$("#modalProses").modal("show");
	$.ajax({
			type:"POST",
            url:"<?php echo Yii::app()->createUrl('/Soa/forceMarryinsurance'); ?>",
			data:"id="+id+"&nota_debet_no="+nota_debet_no+"&kurang_bayar="+kurang_bayar+"&no_type="+no_type,
			dataType:"json",
            success:function(data){
				window.location.href="<?php echo Yii::app()->createUrl('/Soa/internal'); ?>";
				$("#modalProses").modal("hide");
			}
		});//end ajax
}
</script>